package cn.xydpeng.springframework.aop.support.annotation;

import cn.xydpeng.springframework.aop.support.StaticMethodMatcher;
import cn.xydpeng.springframework.util.Assert;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

/**
 * @author xydpeng
 * @version v1.0
 * @date: 2022/10/21
 * @description:
 */
public class AnnotationMethodMatcher extends StaticMethodMatcher {

    private final Class<? extends Annotation> annotationType;
    private final boolean checkInherited;

    public AnnotationMethodMatcher(Class<? extends Annotation> annotationType) {
        this(annotationType, false);
    }


    public AnnotationMethodMatcher(Class<? extends Annotation> annotationType, boolean checkInherited) {
        Assert.notNull(annotationType,"annotationType must not be null");
        this.annotationType = annotationType;
        this.checkInherited = checkInherited;
    }

    @Override
    public boolean matches(Method method, Class<?> targetClass) {
        return method.isAnnotationPresent(this.annotationType);
        //TODO 还要考虑继承、接口、targetClass为代理类等情况
    }
}
